<template>
  <el-container>
    <app-navbar></app-navbar>
    <el-header>
      <h1>用户信息</h1>
    </el-header>
    <el-main>
      <el-card>
        <h3>基本信息</h3>
        <p>用户名: {{ user.username }}</p>
        <p>邮箱: {{ user.email }}</p>

        <h3>收藏的餐厅</h3>
        <el-row :gutter="20">
          <el-col v-for="restaurant in user.favoriteRestaurants" :key="restaurant.id" :span="8">
            <el-card>
              <h4>{{ restaurant.name }}</h4>
              <el-button @click="viewDetails(restaurant.id)">查看详情</el-button>
            </el-card>
          </el-col>
        </el-row>

        <h3>历史操作记录</h3>
        <el-table :data="user.history" style="width: 100%">
          <el-table-column prop="action" label="操作" />
          <el-table-column prop="date" label="日期" />
        </el-table>
      </el-card>
    </el-main>
  </el-container>
</template>

<script>
export default {
  name: 'UserProfile',
  data() {
    return {
      user: {
        username: '不瘦到115不改名',
        email: '1670226583@qq.com',
        favoriteRestaurants: [
          {id: 1, name: '超越火锅鸡'},
          {id: 2, name: '西部牛排'},
        ],
        history: [
          {action: '评论了餐厅A', date: '2023-12-01'},
          {action: '收藏了餐厅B', date: '2023-12-02'},
        ],
      },
    };
  },
  methods: {
    viewDetails(id) {
      this.$router.push({name: 'RestaurantDetail', params: {id}});
    },
  },
};
</script>

<style scoped>
h3 {
  margin-top: 20px;
}
</style>